package scripts.sea;

import api.sea.*;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import util.AssertUtil;
import util.HttpClientUtils;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 待开船列表
 */
public class TestStaySail {
    private String id;
    private String code;
    private static final Logger logger = LoggerFactory.getLogger(TestLogin.class);
    private static final StayPreplanApi stayPreplanApi = new StayPreplanApi();
    private final String number = RandomStringUtils.randomNumeric(8);
    private static final StuffApi stuffApi = new StuffApi();
    private static final StaySailApi staySailApi = new StaySailApi();

    @Test
    public void test_01() throws IOException, URISyntaxException {
        ResponseData responseData = LoginApi.login("admin", "qf123456?");
        String data = responseData.getBody().getJSONObject("data").getString("logistics-token");
        HttpClientUtils.build_header("logistics-token", data);
        HttpClientUtils.build_header("Content-Type", "application/json");
    }

    @Test
    public void test_02() throws IOException, URISyntaxException {
        JSONArray data = new JSONArray();
        Map<String, String> map_data = new HashMap<>();
        map_data.put("cartons", "1");
        map_data.put("length", "1");
        map_data.put("width", "1");
        map_data.put("mark", "Tokyo  Hot");
        map_data.put("weight", "1");
        data.add(map_data);
        Date date = new Date();
        SimpleDateFormat time = new SimpleDateFormat("HH-mm-ss");
        String s = time.format(date);
        String date_time = "QFHY-" + s;
        ResponseData responseData = DelegationApi.delegation("TCY179310074272899092", "COOLPAI", "" + date_time,
                0, "", data, "2021-03-22",
                "LIANYUNGANG", "CHICAGO", "pingming", "2021-04-06", "3", "" + date_time,
                "1", "LWL" + s,
                "100", "1", "0", "", "", "", "",
                1, 1, 1,
                "", "", "US", "", "", "", "", "Tokyo  Hot", "",
                "", "" + date_time,
                "6", "1", "0", 0, "王晓亮", "5409d88922bf4d5187f4",
                "7cd6188ea979499e892e", "黄德挺",
                "7cd6188ea979499e892e", "黄德挺", "创实",
                "CU163032594897092663", 2);
        this.id = responseData.getBody().getJSONObject("data").getString("id");
        this.code = responseData.getBody().getJSONObject("data").getString("entrustmentCode");

    }

    @Test
    public void test_03() throws IOException, URISyntaxException {
        ResponseData responseData = stayPreplanApi.stay_preplan(code, id, number, 1, "1.00", "1.00", "LIANYUNGANG",
                "CHICAGO", "2", "4", "11", "2021-04-14", "2021-04-14", 1);
        logger.info("responseData={}", responseData);
    }

    @Test
    public void test_04() throws IOException, URISyntaxException {
        ResponseData responseData = stuffApi.stuff(number, "1111111", "111111", "2021-04-09", 1);
        logger.info("responseData={}", responseData);
        logger.info("number={}", number);
    }

    @Test
    public void test_05() throws IOException, URISyntaxException {
        String forward = "huodaidanhao" + number;
        ResponseData responseData = staySailApi.stay_sail(number, forward, "isf", "2021-04-09", "xaingguan", "denggfuan", 1);
        logger.info("responseData={}", responseData);
        logger.info("number={}", number);
    }

}
